<?php
namespace common\models;


class TradeGoods extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'trade_goods';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['mch_id', 'btype', 'state'], 'integer'],
            [['value'], 'number'],
            [['type'], 'string', 'max' => 32],
            [['name'], 'string', 'max' => 64],
            [['describe', 'image', 'condition_group', 'condition_rule'], 'string', 'max' => 128],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'goods_id' => 'Goods ID',
            'mch_id' => 'Mch ID',
            'btype' => '操作的账本',
            'type' => '类型 如invest',
            'name' => '名称',
            'value' => '值',
            'describe' => '描述',
            'state' => '1可用 0不可用',
            'image' => 'Image',
            'condition_group' => '条件组  就是有哪些条件',
            'condition_rule' => '条件规则',
        ];
    }    

	/*
		* 数据列表
		* whereArr 条件
		* params 基本参数 包含 field order page limit
		* extends  扩展信息 一些相关的信息
		* 
	*/	
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and'])?$whereArr['and']:[];
		$models = self::queryFormart($model,$where,$params,$whereAnd);
		$model  = $models['model'];
		
		$data  = $model->asarray()->all();
		if(!$data) return array();

		//扩展信息
		if(!$extends) return $data;

		foreach($extends as $extend)
		{

		}

		return $data;	
	}

	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->one();
	}


	public static function getAll($where = [], $field = ['*'])
	{
		return self::find()->select($field)->where($where)->asarray()->all();
	}

}